package model;

/**
 * The Item class works as a bean, and represents an Item that hold a file and a counter which represents the number of times that some word appears in this file.
 * This word is in the inverted index.
 * @author Diogo Kiss and Valerio Lopes
 */
public class Item implements Comparable<Item>
{
	private String fileName;
	private Integer n;
	
	public Item(String fileName,int n)
	{
		this.fileName = fileName;
		this.n = n;
	}
	
	/**
	 * The addOcorrencia method increments the counter of some word related to a file.
	 */
	public void addOcorrencia()
	{
		this.n++;
	}
	
	/**
	 * The setOcorrencia method sets explicitly the number of occurrences of some word related to some file.  
	 */
	public void setOcorrencias(int n)
	{
		this.n = n;
	}
	
	/**
	 * The addOcorrencia sets the bean attribute fileName to a file name given.
	 */
	public void setFile(String fileName)
	{
		this.fileName = fileName;
	}
	
	/**
	 * The getOcorrencias returns the number of occurrences in the object.
	 * @return The number of occurrences in the object.
	 */
	public int getOcorrencias()
	{
		return this.n;
	}
	
	/**
	 * The getFile returns the file name associated to the object.
	 * @return The file name associated to the object.
	 */	
	public String getFile()
	{
		return this.fileName;
	}

	/**
	 * The compareTo implements the Comparable Interface method.
	 * @return The integer result of the comparison.
	 */	
	public int compareTo(Item item)
	{
		int comparacao = n.compareTo(n);
		
		//If the number of occurrences is the same, the file name become the criteria
		if (comparacao == 0) 
		{
			return fileName.compareTo(item.fileName);
		}
		else {
			return comparacao;
		}
		
	}
		
}
